package com.redisMq.consumer.controller;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.lang.NonNull;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 消息监听
 */
public class WlxMessageListener implements MessageListener {

    private static AtomicInteger successCount = new AtomicInteger();
    private static AtomicInteger failCount = new AtomicInteger();

    @Override
    public void onMessage(@NonNull Message message, byte[] pattern) {
        try {
            System.out.println("wlx:" + message);
            successCount.addAndGet(1);
        } catch (Exception e) {
            e.printStackTrace();
            failCount.addAndGet(1);
        }
    }

    public static Map<String, Object> getReceivingQuantity() {
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("SuccessCount", successCount);
        dataMap.put("FailCount", failCount);
        return dataMap;
    }
}